﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <link type="text/css" rel="stylesheet" media="all" href="../styles/global.css"/>
    <link type="text/css" rel="stylesheet" media="all" href="../styles/global_color.css"/>
    <script src="../js/jquery-3.2.1.js"></script>
    <script language="javascript" type="text/javascript">
        $.ajax({
            url: "/selectAllModules",
            type: "post",
            success: function (result) {
                console.log(result)

                if (result.indexOf("角色管理") == -1) {
                    document.getElementById("lia1").style.display = "none"
                }
                if (result.indexOf("管理员管理") == -1) {
                    document.getElementById("lia2").style.display = "none"
                }
                if (result.indexOf("资费管理") == -1) {
                    document.getElementById("lia3").style.display = "none"
                }
                if (result.indexOf("账务账号管理") == -1) {
                    document.getElementById("lia4").style.display = "none"
                }
                if (result.indexOf("业务账号管理") ==-1) {
                    document.getElementById("lia5").style.display = "none"
                }
                if (result.indexOf("账单管理") ==-1) {
                    document.getElementById("lia6").style.display = "none"
                }
                if (result.indexOf("报表管理") == -1) {
                    document.getElementById("lia7").style.display = "none"
                }
            }
        });



//        $.ajax({
//            url: "allservice",
//            type: "post",
//            success: function (result) {
//                console.log(result)
//                var code = result.Code
//                if (code == "0") {
//                    alert(result.message)
//                }
//                var serviceList = result.data;
//                for (var i in serviceList) {
//                    var service = serviceList[i];
//                    addNewTR(service);
//                }
//            }
//        })

        $.ajax({
            url: "servicepage",
            type: "type",
            success: function (result) {
                var roleList = result.list;
                var pages = result.pages;
                var pageNum = result.pageNum;
                var isFirstPage = result.isFirstPage;
                var isLastPage = result.isLastPage;
                for (var i in roleList) {
                    var role = roleList[i];
                    addNewTR(role);
                }
                $("#pages").append("<a id='up'>上一页</a>")

                for (var i = 1; i < pages+1; i++) {
                    if (i == pageNum) {
                        $("#pages").append("<a id=" + i + "; class='current_page'; onclick='changePage(" + i + ")'>" + i + "</a>")
                    } else {
                        $("#pages").append("<a id=" + i + "; onclick='changePage(" + i + ")'>" + i + "</a>")
                    }
                }
                $("#pages").append("<a id='down'>下一页</a>")
                if (!isFirstPage) {
                    var num = pageNum - 1;
                    $("#up").attr("onclick", "changePage(" + num + ")");
                }
                if (!isLastPage) {
                    var num = pageNum + 1;
                    $("#down").attr("onclick", "changePage(" + num + ")");
                }
            }
        })

        function changePage(pagenum) {

            $.ajax({
                url: "servicepage",
                type: "post",
                data: {
                    pagenum: pagenum,
                },
                success: function (result) {
                    $("#servicelist").empty();
                    $("#pages").empty();
                    var roleList = result.list;
                    var pages = result.pages;
                    var pageNum = result.pageNum;
                    var isFirstPage = result.isFirstPage;
                    var isLastPage = result.isLastPage;
                    for (var i in roleList) {
                        var role = roleList[i];
                        addNewTR(role);
                    }
                    $("#pages").append("<a id='up'>上一页</a>")
                    if (!isFirstPage) {
                        var num = pageNum - 1;
                        $("#up").attr("onclick", "changePage(" + num + ")");
                    }
                    for (var i = 1; i < pages+1; i++) {
                        if (i == pageNum) {
                            $("#pages").append("<a id=" + i + "; class='current_page'; onclick='changePage(" + i + ")'>" + i + "</a>")
                        } else {
                            $("#pages").append("<a id=" + i + "; onclick='changePage(" + i + ")'>" + i + "</a>")
                        }
                    }
                    $("#pages").append("<a id='down'>下一页</a>")
                    if (!isLastPage) {
                        var num = pageNum + 1;
                        $("#down").attr("onclick", "changePage(" + num + ")");
                    }
                }
            })
        }


        function addNewTR(service) {
            var account = service.account;
            var cost = service.cost;
            var status = "";
            var operate = "";
            var classvalue = "";

            if (service.status == "0") {
                status = "删除"

            } else if (service.status == "1") {
                status = "开通"
                operate = "暂停"
                classvalue = "btn_start"
            } else if (service.status == "2") {
                status = "暂停"
                operate = "开通"
                classvalue = "btn_pause"
            }



            $("#servicelist").append($("<tr><td><a href=servicedetail?serviceId="+service.serviceId+" title=查看明细>"+service.serviceId+"</a></td><td>" + account.accountId + "</td><td>"+account.idcardNo+"</td><td>" + account.realName + "</td><td>" + service.osUsername + "</td><td>" + status + "</td><td>" + service.unixHost + "</td>" +
                    "<td><a class=summary  onmouseover=showDetail(true,this); onmouseout=showDetail(false,this);>" + cost.name + "</a>" +
                    <!--浮动的详细信息-->
                    "<div class=detail_info>" + cost.descr + "</div></td>" +
                    "<td class=td_modi ><span id='operation" + service.serviceId + "'>" +
                    "<input type=button value=" + operate + " class=" + classvalue + " onclick=setState(" + service.serviceId + "," + service.status + ","+account.accountId+"); />" +
                    "<input type=button value='修改' class=btn_modify onclick=location.href='servicemodi?serviceId=" + service.serviceId + "'; />" +
                    "<input type=button value='删除' class=btn_delete onclick=setState(" + service.serviceId + ",0,"+ account.accountId+"); />" +
                    "</span></td></tr>"));
            if (service.status == 0) {
                document.getElementById("operation" + service.serviceId).style.display = "none";
            }
        }

        //显示角色详细信息
        function showDetail(flag, a) {
            var detailDiv = a.parentNode.getElementsByTagName("div")[0];
            if (flag) {
                detailDiv.style.display = "block";
            }
            else
                detailDiv.style.display = "none";
        }
        //删除
        function deleteAccount() {
            var r = window.confirm("确定要删除此业务账号吗？删除后将不能恢复。");
            document.getElementById("operate_result_info").style.display = "block";
        }

        //开通或暂停
        function setState(serviceId, status,accountId) {
            var r = false;
            if (status == 0){
                r = window.confirm("确定要删除此业务账号吗？删除后将不能恢复。");
            }else {
                r = window.confirm("确定要更改此账务账号吗？");
            }
            if (r) {
                $.ajax({
                    url: "changeservicestatus",
                    type: "post",
                    data: {
                        serviceId: serviceId,
                        status: status,
                        accountId:accountId,
                    },
                    success: function (result) {
                        alert(result.message);
                        window.location.href = "servicelist";
                    }
                })
            }
        }

        function search() {
            $("#servicelist").empty();
            $.ajax({
                url:"searchservice",
                type:"post",
                data:{
                    status:$("#status").val(),
                    osname:$("#osname").val(),
                    ip:$("#ip").val(),
                    cardid:$("#cardid").val(),
                },
                success: function (result) {
                    var code = result.Code
                    if (code == "0") {
                        alert(result.message)
                    }
                    var serviceList = result.data;
                    for (var i in serviceList) {
                        var service = serviceList[i];
                        addNewTR(service);
                    }
                }
            })
        }

    </script>
</head>
<body>
<!--Logo区域开始-->
<div id="header">
    <img src="../images/logo.png" alt="logo" class="left"/>
    <a href="/logout">[退出]</a>
</div>
<!--Logo区域结束-->
<!--导航区域开始-->
<div id="navi">
    <ul id="menu">
        <li><a href="../index.html" class="index_off"></a></li>
        <li id="li1"><a href="rolelist" class="role_off"></a></li>
        <li id="li2"><a href="adminlist" class="admin_off"></a></li>
        <li id="li3"><a href="fee" class="fee_off"></a></li>
        <li id="li4"><a href="accountlist" class="account_off"></a></li>
        <li id="li5"><a href="servicelist" class="service_on"></a></li>
        <li id="li6"><a href="bill" class="bill_off"></a></li>
        <li id="li7"><a href="report" class="report_off"></a></li>
        <li><a href="userinfo" class="information_off"></a></li>
        <li><a href="changepsw" class="password_off"></a></li>
    </ul>
</div>
<!--导航区域结束-->
<!--主要区域开始-->
<div id="main">
    <form action="" method="">
        <!--查询-->
        <div class="search_add">
            <div>OS 账号：<input type="text" value="" id="osname" class="width100 text_search"/></div>
            <div>服务器 IP：<input type="text" value="" id="ip" class="width100 text_search"/></div>
            <div>身份证：<input type="text" value="" id="cardid" class="text_search"/></div>
            <div>状态：
                <select class="select_search" id="status">
                    <option>全部</option>
                    <option>开通</option>
                    <option>暂停</option>
                    <option>删除</option>
                </select>
            </div>
            <div><input type="button" value="搜索" class="btn_search" onclick="search()"/></div>
            <input type="button" value="增加" class="btn_add" onclick="location.href='serviceadd';"/>
        </div>
        <!--删除的操作提示-->
        <div id="operate_result_info" class="operate_success">
            <img src="../images/close.png" onclick="this.parentNode.style.display='none';"/>
            删除成功！
        </div>
        <!--数据区域：用表格展示数据-->
        <div id="data">
            <table id="datalist">
                <tr>
                    <th class="width50">业务ID</th>
                    <th class="width70">账务账号ID</th>
                    <th class="width150">身份证</th>
                    <th class="width70">姓名</th>
                    <th>OS 账号</th>
                    <th class="width50">状态</th>
                    <th class="width100">服务器 IP</th>
                    <th class="width100">资费</th>
                    <th class="width200"></th>
                </tr>
                <tbody id="servicelist">

                </tbody>

            </table>
            <p>业务说明：<br/>
                1、创建即开通，记载创建时间；<br/>
                2、暂停后，记载暂停时间；<br/>
                3、重新开通后，删除暂停时间；<br/>
                4、删除后，记载删除时间，标示为删除，不能再开通、修改、删除；<br/>
                5、业务账号不设计修改密码功能，由用户自服务功能实现；<br/>
                6、暂停和删除状态的账务账号下属的业务账号不能被开通。</p>
        </div>
        <!--分页-->
        <div id="pages">

        </div>
    </form>
</div>
<!--主要区域结束-->
<div id="footer">
    <p>[源自北美的技术，最优秀的师资，最真实的企业环境，最适用的实战项目]</p>
    <p>版权所有(C)云科技有限公司 </p>
</div>
</body>
</html>
